package cn.wolfcode.shop.cloud.mq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(
        topic = MQCounts.CREATE_ORDER,
        consumerGroup = MQCounts.ORDER_SUCCESS_GROUP,
        selectorExpression = MQCounts.ORDER_SUCCESS_TAG
)
public class OrderSuccessMQListener implements RocketMQListener<Map> {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void onMessage(Map data) {
        System.out.println("成功队列");
        //发送延时消息
        rocketMQTemplate.syncSend(MQCounts.ORDER_SUCCESS_DELAY_DEST,MessageBuilder.withPayload(data).build(),5000, 3);
    }
}
